package com.xoms.admin.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xoms.admin.model.ProCheckBean;
import com.xoms.admin.model.ProCheckProInfoBean;
import com.xoms.admin.model.vo.AuditCheckBean;
import com.xoms.admin.model.vo.BatchCheckBean;
import com.xoms.admin.persist.dao.ProCheckDao;
import com.xoms.util.StringUtil;

@Repository
public class ProCheckImpl extends BaseImpl implements ProCheckDao {
	
	final String NAME_SPACE = NAME_SPACE_HEADER + ".ProCheckMapper";

	@Override
	public int selectCount(String key, String storeId, String startTime, String endTime) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (!StringUtil.isEmpty(key)) {
			params.put("key", key);
		}
		if (!StringUtil.isEmpty(startTime)) {
			params.put("startTime", startTime);
		}
		if (!StringUtil.isEmpty(endTime)) {
			params.put("endTime", endTime);
		}
		if (!StringUtil.isEmpty(storeId)) {
			params.put("storeHouseId", storeId);
		}
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", params);

	}

	@Override
	public List<ProCheckBean> selectList(String key, int page, int pageSize, String storeId, String startTime,
			String endTime) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("start", page * pageSize);
		params.put("length", pageSize);
		if (!StringUtil.isEmpty(key)) {
			params.put("key", key);
		}
		if (!StringUtil.isEmpty(startTime)) {
			params.put("startTime", startTime);
		}
		if (!StringUtil.isEmpty(endTime)) {
			params.put("endTime", endTime);
		}
		if (!StringUtil.isEmpty(storeId)) {
			params.put("storeHouseId", storeId);
		}
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", params);

	}

	@Override
	public int selectDetailCount(String cid) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (!StringUtil.isEmpty(cid)) {
			params.put("cid", cid);
		}
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectDetailCount", params);
	
	}

	@Override
	public List<ProCheckProInfoBean> selectDetailList(String cid, int page, int pageSize, int paging) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("start", page * pageSize);
		params.put("length", pageSize);
		if (!StringUtil.isEmpty(cid)) {
			params.put("cid", cid);
		}
		params.put("paging", paging);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectDetailList", params);

	}

	@Override
	public ProCheckBean selectOneById(String cid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneById", cid);
	}
	
	
	@Override
	public int del(String cid) {
		return sqlSessionTemplate.delete(NAME_SPACE + ".delete", cid);
	}

	@Override
	public int delDetails(String cid) {
		return sqlSessionTemplate.delete(NAME_SPACE + ".delDetails", cid);
	}

	@Override
	public int updateSubmitStatus(String cid, int status) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("cid", cid);
		params.put("status", status);
		return sqlSessionTemplate.update(NAME_SPACE + ".updateSubmitStatus", params);
	}

	@Override
	public String selectMaxCheckNoInYear() {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectMaxCheckNoInYear");
	}

	@Override
	public int insert(ProCheckBean data) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", data);
	}

	@Override
	public int update(ProCheckBean data) {
		return sqlSessionTemplate.update(NAME_SPACE + ".update", data);
	}

	@Override
	public int replaceBatchDetail(List<BatchCheckBean> batch) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("list", batch);
		return sqlSessionTemplate.insert(NAME_SPACE + ".replaceBatchDetail", params);
	}

	@Override
	public AuditCheckBean selectAuditCheckDetailsById(String aid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectAuditCheckDetailsById", aid);
	}


}
